package com.jit.monitor.presenter;

import com.jit.baselib.bean.response.BaseListResponse;
import com.jit.baselib.ui.base.BaseActivity;
import com.jit.baselib.ui.base.BaseObserver;
import com.jit.baselib.ui.base.BasePresenter;
import com.jit.baselib.ui.base.ExceptionHandle;
import com.jit.monitor.base.ApiRetrofit;
import com.jit.monitor.commom.AppConstant;
import com.jit.monitor.model.response.WarnHistoryBean;
import com.jit.monitor.view.WarnHsyAtView;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * @author crazyZhangxl on 2019/1/22.
 * Describe:
 */
public class WarnHsyAtPresenter extends BasePresenter<WarnHsyAtView>{

    public WarnHsyAtPresenter(BaseActivity context) {
        super(context);
    }


    public void queryWarnHsyByPage(String cameraID,int page){
        ApiRetrofit.getInstance().queryWnHsyByCameraID(cameraID,page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseListResponse<WarnHistoryBean>>() {
                    @Override
                    public void onNext(BaseListResponse<WarnHistoryBean> warnHistoryBeanBaseListResponse) {
                        if (AppConstant.REQUEST_SUCCESS == warnHistoryBeanBaseListResponse.getCode()){
                            getView().queryHsySuccess(warnHistoryBeanBaseListResponse.getData());
                        }else {
                            getView().queryHsyFailure(warnHistoryBeanBaseListResponse.getMsg());
                        }
                    }

                    @Override
                    public void onError(ExceptionHandle.ResponseException exception) {
                        getView().queryHsyFailure(exception.getErrorInfo());
                    }
                });
    }
}
